package com.gpframework.common.core.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.annotation.Excel;
import com.gpframework.common.annotation.Excel.ColumnType;
import com.gpframework.common.constant.BrandConstants;
import com.gpframework.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

/**
 * 角色表 sys_role
 *
 * @Author gpframework
 */
public class SysRole extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 角色ID
     */
    @ApiModelProperty("角色ID")
    @Excel(name = "角色序号", cellType = ColumnType.NUMERIC)
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long brandRoleId;

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long roleId;

    /**
     * 品牌id
     */
    @ApiModelProperty("品牌id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long brandId;

    /**
     * 部门id
     */
    @ApiModelProperty("部门id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long branddeptId;

    /**
     * 门店id
     */
    @ApiModelProperty("门店id")
    private Long storeId = BrandConstants.DEFAULT_BRAND_ID;

    /**
     * 角色名称
     */
    @Excel(name = "角色名称")
    @ApiModelProperty("角色名称")
    private String roleName;

    /**
     * 门店名称
     */
    @Excel(name = "门店名称")
    @ApiModelProperty("门店名称")
    private String storeName;

    /**
     * 角色权限
     */
    @Excel(name = "角色权限")
    @ApiModelProperty("角色权限")
    private String roleKey;

    /**
     * 角色排序
     */
    @Excel(name = "角色排序")
    @ApiModelProperty("角色排序")
    private String roleSort;

    /**
     * 数据范围（1：所有数据权限；2：自定义数据权限；3：本部门数据权限；4：本部门及以下数据权限）
     */
    @Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限")
    @ApiModelProperty("数据范围")
    private String dataScope;

    /**
     * 菜单树选择项是否关联显示（ 0：父子不互相关联显示 1：父子互相关联显示）
     */
    @ApiModelProperty("菜单树选择项是否关联显示")
    private boolean menuCheckStrictly;

    /**
     * 部门树选择项是否关联显示（0：父子不互相关联显示 1：父子互相关联显示 ）
     */
    @ApiModelProperty("部门树选择项是否关联显示")
    private boolean deptCheckStrictly;

    /**
     * 角色状态（0正常 1停用）
     */
    @Excel(name = "角色状态", readConverterExp = "0=正常,1=停用")
    @ApiModelProperty("角色状态")
    private String status;

    /**
     * 删除标志（0代表存在;2代表删除）
     */
    private Integer delStatus;

    /**
     * 用户是否存在此角色标识 默认不存在
     */
    private boolean flag = false;

    /**
     * 菜单组
     */
    @ApiModelProperty("菜单组")
    private Long[] menuIds;

    /**
     * 是否可删除 0是 1否
     */
    private Integer isDel;

    /**
     * 部门组（数据权限）
     */
    @ApiModelProperty("部门组")
    private Long[] deptIds;

    /**
     * 微信菜单id
     */
    @ApiModelProperty("微信菜单id")
    private Long[] wxMenuIdList;

    /**
     * 部门id
     */
    @ApiModelProperty("部门id")
    private Long brandDeptId;

    /**
     * 部门名称
     */
    @ApiModelProperty("部门名称")
    private String brandDeptName;

    public SysRole() {

    }

    public SysRole(Long brandId, String roleName, String roleKey, String roleSort, String dataScope, boolean menuCheckStrictly, boolean deptCheckStrictly) {
        this.brandId = brandId;
        this.roleName = roleName;
        this.roleKey = roleKey;
        this.roleSort = roleSort;
        this.dataScope = dataScope;
        this.menuCheckStrictly = menuCheckStrictly;
        this.deptCheckStrictly = deptCheckStrictly;
        this.status = "0";
    }

    public SysRole(Long roleId) {
        this.brandRoleId = roleId;
    }

    public Long getBrandRoleId() {
        return brandRoleId;
    }

    public void setBrandRoleId(Long brandRoleId) {
        this.brandRoleId = brandRoleId;
    }

    public Long getBrandId() {
        return brandId;
    }

    public void setBrandId(Long brandId) {
        this.brandId = brandId;
    }

    public boolean isAdmin() {
        return isAdmin(this.brandRoleId);
    }

    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public static boolean isAdmin(Long roleId) {
        return roleId != null && 1L == roleId;
    }

    @NotBlank(message = "角色名称不能为空")
    @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符")
    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    //    @NotBlank(message = "权限字符不能为空")
    @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符")
    public String getRoleKey() {
        return roleKey;
    }

    public void setRoleKey(String roleKey) {
        this.roleKey = roleKey;
    }

    @NotBlank(message = "显示顺序不能为空")
    public String getRoleSort() {
        return roleSort;
    }

    public void setRoleSort(String roleSort) {
        this.roleSort = roleSort;
    }

    public String getDataScope() {
        return dataScope;
    }

    public void setDataScope(String dataScope) {
        this.dataScope = dataScope;
    }

    public boolean isMenuCheckStrictly() {
        return menuCheckStrictly;
    }

    public void setMenuCheckStrictly(boolean menuCheckStrictly) {
        this.menuCheckStrictly = menuCheckStrictly;
    }

    public boolean isDeptCheckStrictly() {
        return deptCheckStrictly;
    }

    public void setDeptCheckStrictly(boolean deptCheckStrictly) {
        this.deptCheckStrictly = deptCheckStrictly;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Integer getDelStatus() {
        return delStatus;
    }

    public void setDelStatus(Integer delStatus) {
        this.delStatus = delStatus;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public Long[] getMenuIds() {
        return menuIds;
    }

    public void setMenuIds(Long[] menuIds) {
        this.menuIds = menuIds;
    }

    public Long[] getDeptIds() {
        return deptIds;
    }

    public void setDeptIds(Long[] deptIds) {
        this.deptIds = deptIds;
    }

    public Integer getIsDel() {
        return isDel;
    }

    public void setIsDel(Integer isDel) {
        this.isDel = isDel;
    }

    public Long getStoreId() {
        return storeId;
    }

    public void setStoreId(Long storeId) {
        this.storeId = storeId;
    }

    public Long[] getWxMenuIdList() {
        return wxMenuIdList;
    }

    public void setWxMenuIdList(Long[] wxMenuIdList) {
        this.wxMenuIdList = wxMenuIdList;
    }

    public Long getBrandDeptId() {
        return brandDeptId;
    }

    public void setBrandDeptId(Long brandDeptId) {
        this.brandDeptId = brandDeptId;
    }

    public String getBrandDeptName() {
        return brandDeptName;
    }

    public void setBrandDeptName(String brandDeptName) {
        this.brandDeptName = brandDeptName;
    }

    public Long getBranddeptId() {
        return branddeptId;
    }

    public void setBranddeptId(Long branddeptId) {
        this.branddeptId = branddeptId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("roleId", getBrandRoleId())
                .append("brandId", getBrandId())
                .append("storeId", getStoreId())
                .append("roleName", getRoleName())
                .append("roleKey", getRoleKey())
                .append("roleSort", getRoleSort())
                .append("dataScope", getDataScope())
                .append("menuCheckStrictly", isMenuCheckStrictly())
                .append("deptCheckStrictly", isDeptCheckStrictly())
                .append("status", getStatus())
                .append("delStatus", getStatus())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .append("remark", getRemark())
                .append("isDel", getIsDel())
                .toString();
    }
}
